-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
14-mj111 #223
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΈμ ν κ°μ΄ μμλμ§ μμλμ§ νμΈνλ κ³Όμ μ booleanμΌλ‘ μ²λ¦¬νλ €νλλ°...
λ§μ§λ§ μμ μμ μ μ©λμ§ μλ λΆλΆμ΄ μ겨μ, κ·Έλ₯ zero_cnt(zeroNum
)μ λ§λ€μ΄μ ν΄μ£ΌλκΉ λ°λ‘ ν΅κ³Όλμ΅λλ€!
μ 체 μ½λ
import sys
sys.setrecursionlimit(100000)
input = open("input.txt").readline
N, M, T = map(int, input().split())
target = [list(map(int,input().split())) for _ in range(N)]
offset = [(1, 0), (0,1), (-1,0), (0,-1)]
for _ in range(T):
# λ리기
disk, dir, cnt = map(int,input().split())
cnt = cnt if dir else M-cnt
for i in range(disk, N+1, disk):
target[i-1] = target[i-1][cnt:] + target[i-1][:cnt]
# μΈμ μμ κΈ°
def dfs(x, y, num):
zero_cnt = 0
for dx, dy in offset:
nx = x + dx
ny = (y + dy + M)%M
if nx < 0 or nx == N or target[nx][ny] == 0:
continue
if target[nx][ny] == num:
if not target[x][y]:
zero_cnt += 1
zero_cnt += 1
target[x][y] = 0
target[nx][ny] = 0
zero_cnt += dfs(nx, ny, num)
return zero_cnt
zero_cnt = 0
for i in range(N):
for j in range(M):
if not target[i][j] == 0:
zero_cnt += dfs(i, j, target[i][j])
# μΈμ μμ μ, νκ· ν΄μ κ° λ³κ²½νκΈ°
if not zero_cnt:
left_cnt = sum([sum([0 if j==0 else 1 for j in i])for i in target])
if not left_cnt:
break
total = sum([sum(i) for i in target]) / left_cnt
for k1, v1 in enumerate(target):
for k2, v2 in enumerate(v1):
if 0 < v2 < total:
target[k1][k2] += 1
elif v2 > total:
target[k1][k2] -= 1
print(sum([sum(i) for i in target]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π λ¬Έμ λ§ν¬
λ°±μ€ - μν λ리기
https://www.acmicpc.net/problem/17822
βοΈ μμλ μκ°
1μκ°
β¨ μλ μ½λ
ν΄λΉ λ¬Έμ λ,
μ£Όμ΄μ§ μνμμ νμ μν€κ³ , μΈμ ν μ μλΌλ¦¬ μμ λμ§,
νμ μν€κ³ , μΈμ ν μ μκ° μμΌλ©΄ νκ· μΌλ‘ μΉννλ©°
μ΅μ’ μνμμ μ ν μ μμ ν©μ μΆλ ₯νλ λ¬Έμ μ λλ€.
λ¨Όμ μν μ μλ€μ μ λ ₯λ°μ΅λλ€.
μ΄ν μ£Όμ΄μ§ κ°μ λ°λΌ νμ μ μμΌμ€λλ€.
νμ νμμ μμ§ μ«μκ° λ¨μμλμ§ νμΈν©λλ€.
λ§μ½ μ«μκ° λ¨μμκ³ ,
μΈμ ν κ°μ μ«μκ° μ‘΄μ¬νλ€λ©΄ 0μΌλ‘ λ§λ€μ΄μ€λλ€.
λ§μ½ λ§μ½ μ«μκ° λ¨μμκ³ ,
μΈμ ν κ°μ μ«μκ° μλ€λ©΄ νκ· κ°μΌλ‘ μΉνν΄ μ€λλ€.
μ£Όμ΄μ§ νμ μ λ€ λ§μ³€μΌλ©΄, νμ νμ μλ μ«μλ€μ ν©μ μΆλ ₯ν΄μ€λλ€.
μνμ μ«μλ₯Ό λ리λ λ°©λ²μ κ°λ¨ν©λλ€.
μ£Όμ΄μ§ μκ³λ°©ν₯μ λ§μΆ° μ£Όμ΄μ§ λ§νΌ μ΄λμν΅λλ€.
μΈμ ν μ«μλ₯Ό μ°Ύμ 0μΌλ‘ λ§λλ μμ μ
μ΄μμ λ¨Όμ μΈμ μ νμΈνκ³ , μ΄ν νμμ μΈμ μ νμΈνμ¬ 0μΌλ‘ μΉνν΄μ£Όλ©΄ λ©λλ€.
π μλ‘κ² μκ²λ λ΄μ©
빑ꡬνμμ μ£Όμ΄μ§ μμλλ‘ μ°¨κ·Όμ°¨κ·Ό ꡬνν λ
λ©μΈ λ©μλμμ μΌλ¨ μμμ λ©μλλ₯Ό νΈμΆνλλ‘ νκ³ λμ μ΄νμ μμΈν ꡬνμ νλ λ°©μμΌλ‘ νλκ² κ°μ₯ λΉ λ₯Έ λ°©λ²μΈ κ² κ°μ΅λλ€.